<%@ include file="/common/taglibs.jsp" %>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						$('#pageTitle')
								.text(
										'<spring:message code="editCipeprojectSummary.heading" />');
						$("#editCipeprojectForm").validate({
							rules : {
								partner : {
									required : true
								},
								acronym : {
									required : true
								},
								costCenterNumber : {
									required : true
								},
								projectTitle : {
									required : true
								},
								donoraward : {
									required : true
								},
								projectStartDate : {
									required : true
								},
								projectEndDate : {
									required : true
								},
								cipeprojecttype : {
									required : true
								},
								cipeprojectstatus : {
									required : true
								},
								region : {
									required : true
								},
								country : {
									required : true
								},
								seniorProgramOfficer : {
									required : true
								},
								programOfficer : {
									required : true
								},
								programAssistant : {
									required : true
								},
								managementFunds : {
									required : true
								}
							}
						});
						
				    	$('.attachmentPath').click(function() {
							var fileName = $('div', this).text();
							window.open("<c:url value='/openFile.do' />?fileName=" + fileName, "_blank", "left=20, top=20, width=700, height=700, toolbar=1, resizable=0").focus();
						});					
					});
// 	$(function() {
// 		$("#projectStartDate").datepicker();
// 	});

// 	$(function() {
// 		$("#projectEndDate").datepicker();
// 	});
	$('.add-partner-link').click(function() {
		loadDiv('content', 'showAddPartner.do');
	});
	$("#fiscalyear").datepicker({
		dateFormat : 'yy'
	});
	$('.edit-cipeproject-link').click(
			function() {
				loadDiv('content', 'showEditCipeproject.do?id='
						+ $(this).attr('cipeprojectId'));
			});
	function getFiscalYear() {
		var str1 = document.getElementById("projectStartDate").value;

		var mon1 = parseInt(str1.substring(0, 2), 10);
		var dt1 = parseInt(str1.substring(3, 5), 10);
		var yr1 = parseInt(str1.substring(6, 10), 10);
		var dt2 = 1;
		var mon2 = 10;
		var date1 = new Date(yr1, mon1, dt1);
		var date2 = new Date(yr1, mon2, dt2);
		if (date2 < date1) {
			document.getElementById("fiscalyear").value = yr1;
		} else {
			document.getElementById("fiscalyear").value = parseInt(yr1) - 1;
		}
	}
	$('#view-modifications').click(
			function() {
				loadDiv('content', 'showCipeprojectModifications.do?id='
						+ $(this).attr('cipeprojectId'));
			});
	$('#view-cipeprojectdetail').click(
			function() {
				loadDiv('content', 'showEditCipeprojectDetail.do?id='
						+ $(this).attr('cipeprojectId'));
			});
	$('#view-knowledgemanagement').click(
			function() {
				loadDiv('content', 'showEditKnowledgeManagement.do?id='
						+ $(this).attr('cipeprojectId'));
			});
	$('#view-knowledgemanagementInfo').click(
			function() {
				loadDiv('content', 'showEditKnowledgeManagement.do?id='
						+ $(this).attr('cipeprojectId'));
			});
	$('#view-rollup').click(
			function() {
				var proId=$(this).attr('cipeprojectId');
				if(proId==null ||proId==''){
					 alert("This Project is not Rollup with any other Project.");
					 return false;
				}else{
					loadDiv('content', 'showCipeprojectSummary.do?id='
							+ proId);
					return true;
				}
			});
	$('#view-loggedpayments').click(
			function() {
				loadDiv('content',
						'showCipeprojectPaymentRequestLineItems.do?id='	
						+ $(this).attr('cipeprojectId'));
			});
	$('.close-button').click(function() {
		window.location = '../secure/showDashboard.do';
	});
	$('.edit-partnergrant-link').click(
			function() {
				loadDiv('content', 'showEditPartnergrantView.do?id='
						+ $(this).attr('partnergrantId'));
			});
</script>
<div id="editCipeprojectSummaryDiv">
	<form:form name="editCipeprojectForm" id="editCipeprojectForm" action="saveCipeproject.do" method="post" modelAttribute="cipeproject">
		<form:hidden path="id" />
		<div class="main_form">
			<div class="form_head">
				<div class="floatL" style="padding-top: 5px;">
					<td colspan="2" valign="top">
                      <input type="button" id="view-loggedpayments" cipeprojectId="${cipeproject.id}" value="<spring:message code="editCipeprojectSummary.link.payments" />" />&nbsp;
                      <input type="button" id="view-knowledgemanagement"	cipeprojectId="${cipeproject.id}" value="<spring:message code="editCipeprojectSummary.link.knowledgemanagement" />"/>&nbsp;
                    <c:if test="${isGrantUser || isStaffUser || isKmUser || isSrManagementUser || isAdminUser }">
                      <input type="button" id="view-modifications" cipeprojectId="${cipeproject.id}" value="<spring:message code="editCipeprojectSummary.link.modifications" />" />&nbsp;
                    </c:if>
                      <input type="button" id="view-rollup" cipeprojectId="${cipeproject.masterProject.id}" value="<spring:message code="editCipeprojectSummary.link.rollup" />"/>&nbsp;
                      <input type="button" id="view-cipeprojectdetail" cipeprojectId="${cipeproject.id}" value="<spring:message code="editCipeprojectSummary.link.projectdetails" />" />&nbsp;
                    </td>
					<td valign="top"></td>
				</div>
				<input type="button" class="close-button gray_btn floatR" value="Close Form" /><br class="clear" />
			</div>
			<div class="form_cont">				
				<table>
					<tr><td></td><tr>
					<tr>
						<td colspan="4">
							<table cellpadding="2" cellspacing="2" align="right">
			   					 <tr>
									<td colspan="3" style="padding-left:175px"><b>Solomon Data</b></td>									
								 </tr>
								 <c:choose>
								 		<c:when test="${cipeproject.solomon.costcenternumber == null}">
											<tr><td style="padding-right:150px ">No Solomon data present for this Project ID !</td>							
											</tr>	
						
										</c:when>						
										<c:otherwise>
											<tr>										
												<td><b>Expenses as of</b></td>
												<td><b>Cost Center</b></td>
												<td><b>Description</b></td>
												<td><b>Amount</b></td>								
											</tr>
											<tr>
												<td><fmt:formatDate type="date" pattern="MM/dd/yyyy" value="${cipeproject.solomon.date}" /></td>
												<td>${cipeproject.solomon.costcenternumber}</td>									
												<td>Salary and Fringe as of <fmt:formatDate type="date" pattern="MM/dd/yyyy" value="${cipeproject.solomon.date}" /></td>
												<td><fmt:formatNumber type="currency" value="${cipeproject.solomon.totalAmount}"  pattern="$#,##0.##;" /></td>							
											</tr>
										<tr></tr>
									</c:otherwise>
								</c:choose>				
							</table>
						</td>
					</tr>
					<tr></tr>
					<tr>
						<td width="60%" valign="top">
							<table>
								<!-- 
			<tr class="row">
				<td class="menu-heading" colspan="3"><spring:message code="editCipeprojectSummary.heading" /></td>
			</tr>
			 -->
								<tr class="row">
									<td class="label">&nbsp;</td>
									<td class="input-field" colspan="2"><%@ include file="/common/messages.jsp"%></td>
								</tr>
								<tr class="row">
									<td class="label"><spring:message code="editCipeproject.label.acronym" /></td>
									<td class="input-field"><form:input path="acronym" readonly="true" cssClass="input-full-width-req full_text_grey" /></td>
									<td><form:errors path="acronym" cssClass="error" /></td>
								</tr>
								<tr class="row">
									<td class="label"><spring:message code="editCipeproject.label.projectTitle" /></td>
									<td class="input-field"><form:input path="projectTitle" readonly="true" cssClass="input-full-width-req full_text_grey" /></td>
									<td><form:errors path="projectTitle" cssClass="error" /></td>
								</tr>
								<tr class="row">
									<td class="label"><spring:message code="editCipeproject.label.projectID" /></td>
									<td class="input-field"><form:input path="projectID" readonly="true" cssClass="input-full-width full_text_grey" /></td>
									<td><form:errors path="projectID" cssClass="error" /></td>
								</tr>
								<tr class="row">
									<td class="label"><spring:message code="editCipeproject.label.startDate" /></td>
									<td class="input-field"><form:input path="projectStartDate" readonly="true" cssClass="input-full-width-req full_text_grey" onchange="getFiscalYear()" /></td>
									<td><form:errors path="projectStartDate" cssClass="error" /></td>
								</tr>
								<tr class="row">
									<td class="label"><spring:message code="editCipeproject.label.endDate" /></td>
									<td class="input-field"><form:input path="projectEndDate" readonly="true" cssClass="input-full-width-req full_text_grey" /></td>
									<td><form:errors path="projectEndDate" cssClass="error" /></td>
								</tr>
								<tr class="row">
									<td class="label"><spring:message code="editCipeproject.label.type" /></td>
									<td class="input-field"><form:input path="cipeprojecttype.displayName" cssClass="input-full-width full_text_grey" readonly="true" /></td>
									<td><form:errors path="cipeprojecttype.id" cssClass="error" /></td>
								</tr>
								<tr class="row">
									<td class="label"><spring:message code="editCipeproject.label.status" /></td>
									<td class="input-field"><form:input path="cipeprojectstatus.displayName" cssClass="input-full-width full_text_grey" readonly="true" /></td>
									<td><form:errors path="cipeprojecttype.id" cssClass="error" /></td>
								</tr>
							</table>
						</td>						
						<td style="padding-left:1px; float: left;" width="100%" valign="top">
							<table style="cell-spacing:3px">
								<tr>
									<th></th>
									<th>Budget Amount</th>
									<th>Disbursed Amount</th>
									<th>Balance Amount</th>
								</tr>
								<tr>
									<td><b>Management Amnt:</b></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.projectBudgetAmount}" pattern="$#,##0.##;" /></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.totalManagementSolomonDisbursedAmount}"  pattern="$#,##0.##;" /></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.projectBalanceAmount}" pattern="$#,##0.##;" /></td>
								</tr>
								<tr>
									<td><b>Partner Grant/s:</b></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.totalPartnerBudgetAmount}" pattern="$#,##0.##;" /></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.totalPartnerDisbursedAmount}"  pattern="$#,##0.##;" /></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.totalPartnerBalanceAmount}" pattern="$#,##0.##;" /></td>
								</tr>
								<tr>
									<td><b>Total:</b></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.totalProjectPartnerBudgetAmount}" pattern="$#,##0.##;" /></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.totalManagementSolomonPartnerDisbursedAmount}" pattern="$#,##0.##;" /></td>
									<td><fmt:formatNumber type="currency" value="${cipeproject.totalProjectPartnerBalanceAmount}" pattern="$#,##0.##;" /></td>
								</tr>
								<tr>
									<td><b>#Linked Sub-Grants:</b></td>
									<td>${fn:length(childCipeprojectList)}</td>
									<td></td>
									<td></td>
								</tr>
								<tr><td></td></tr>								
							</table>
						</td>
					</tr>
				</table>
				<div>
					<b><spring:message code="editCipeprojectDetail.heading.grants" /></b>
				</div>
				<div id="cipeprojectListDiv" class="hastable" style="overflow: auto">
					<table class="tablesorter">
						<thead>
							<tr>
								<th><spring:message code="partnergrantlist.table.heading.projectID" /></th>
								<th><spring:message code="partnergrantlist.table.heading.projectSponsor" /></th>
								<th><spring:message code="partnergrantlist.table.heading.acronym" /></th>
								<th><spring:message code="partnergrantlist.table.heading.budget" /></th>
								<th><spring:message code="partnergrantlist.table.heading.disbursed" /></th>
								<th><spring:message code="partnergrantlist.table.heading.balance" /></th>
								<th><spring:message code="partnergrantlist.table.heading.projectTitle" /></th>
								<th><spring:message code="partnergrantlist.table.heading.startDate" /></th>
								<th><spring:message code="partnergrantlist.table.heading.endDate" /></th>
								<th><spring:message code="partnergrantlist.table.heading.status" /></th>
								<th><spring:message code="partnergrantlist.table.heading.ingrants" /></th>
								<th><spring:message code="partnergrantlist.table.heading.agreement" /></th>
								<th><spring:message code="partnergrantlist.table.heading.autho" /></th>
								<th><spring:message code="partnergrantlist.table.heading.bank" /></th>
								<!-- <th><spring:message code="partnergrantlist.table.heading.type" /></th>
								<th><spring:message code="partnergrantlist.table.heading.programOfficer" /></th>
								<th><spring:message code="partnergrantlist.table.heading.region" /></th>
								<th><spring:message code="partnergrantlist.table.heading.country" /></th>
								<th><spring:message code="partnergrantlist.table.heading.managementFunds" /></th> -->
								<%--<th><spring:message code="partnergrantlist.table.heading.edit" /></th> --%>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${childCipeprojectList}" var="cipeproject">
								<tr>
									<td>${cipeproject.projectID}</td>
									<td><a href="javascript://" class="edit-partnergrant-link" partnergrantId="${cipeproject.id}">${cipeproject.acronym} <spring:message code="label.separator" /> ${cipeproject.partner.partnerName}
									</a></td>
									<td>${cipeproject.acronym}</td>
									<%--<td><a href="javascript://" class="edit-partnergrant-link" partnergrantId="${cipeproject.id}">${cipeproject.projectID}</a></td> --%>
									<td><spring:message code="label.dollar" />${cipeproject.partnerBudgetAmount}</td>
									<td><spring:message code="label.dollar" />${cipeproject.partnerDisbursedAmount}</td>
									<td><spring:message code="label.dollar" />${cipeproject.partnerBalanceAmount}</td>
									<td>${cipeproject.projectTitle}</td>
									<td><fmt:formatDate pattern="MM-dd-yyyy" value="${cipeproject.projectStartDate}" /></td>
									<td><fmt:formatDate pattern="MM-dd-yyyy" value="${cipeproject.projectEndDate}" /></td>
									<td>${cipeproject.cipeprojectstatus.displayName}</td>
									<td>${cipeproject.receivedingrantsforapproval}</td>
									<td>${cipeproject.receiptOfSignedAgreement}</td>
									<td>${cipeproject.receiptOfSignatureAuthorization}</td>
									<td>${cipeproject.receiptOfBankInformation}</td>
									<!--<td>${cipeproject.cipeprojecttype.displayName}</td>
									<td>${cipeproject.programOfficer.fullName}</td>
									<td>${cipeproject.region.displayName}</td>
									<td>${cipeproject.country.displayName}</td>
									<td>${cipeproject.managementFunds}</td>-->
									<%--<td><a href="javascript://" class="edit-partnergrant-link" partnergrantId="${cipeproject.id}"><spring:message code="partnergrantlist.table.link.edit" /></a></td> --%>
								</tr>
							</c:forEach>
						</tbody>
					</table>
				</div>
				<br class="clear" /> <br class="clear" /> <br class="clear" /> <br class="clear" />
            <c:if test="${isGrantUser || isStaffUser || isKmUser || isSrManagementUser || isAdminUser }">
				<div>Project modifications</div>
				<table class="tablesorter">
					<thead>
						<tr>
							<th>ID</th>
							<th>Modification Type</th>
							<th>Modified From</th>
							<th>Modified To</th>
							<th>Modified Date</th>
							<th>Modified By</th>
							<th>File Location of Modified Document</th>
						</tr>
					</thead>
					<tbody>
						<c:choose>
							<c:when test="${fn:length(cipeproject.cipeprojectmodifications) > 0}">
								<c:forEach items="${cipeproject.cipeprojectmodifications}" var="modification">
									<tr>
										<td>${modification.id}</td>
										<td>${modification.modificationType.modificationTypeDesc}</td>
										<td>${modification.modifiedFrom}</td>
										<td>${modification.modifiedTo}</td>
										<td>${modification.formattedModifiedDate}</td>
										<td>${modification.modifiedBy.fullName}</td>
										<td><a href="#" onclick="return false;" class="attachmentPath"><div>${modification.attachment}</div></a></td>
									</tr>
								</c:forEach>
							</c:when>
							<c:otherwise>
								<tr>
									<td colspan="7" style="padding-left: 10px;">No modifications found.</td>
								</tr>
							</c:otherwise>
						</c:choose>
					</tbody>
				</table>
              </c:if>
			</div>
		</div>
	</form:form>
	<div>
		<div id="cipeprojectawardListPager"></div>
	</div>
</div>
